package com.shopping.dao;

import com.shopping.pojo.CorporationRole;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
@Mapper
public interface CorporationRoleDao {

    String TABLE_NAME = "corporation_role";
    String INSERT_FIELDS = "id, id_number, corporation_name, corporation_address, corporation_introduce";
    String SELECT_FIELDS = "id, id_number idNumber, corporation_name corporationName, corporation_address corporationAddress, " +
            "corporation_introduce corporationIntroduce";
    String SELECT_MESSAGE= "id, corporation_name corporationName, corporation_address corporationAddress, " +
            "corporation_introduce corporationIntroduce";

    @Insert({"insert into ", TABLE_NAME, " (", INSERT_FIELDS, ") values(#{id}, #{idNumber}, #{corporationName}, #{corporationAddress}, #{corporationIntroduce})"})
    int insert(CorporationRole corporationRole);

    @Select({"select ", SELECT_FIELDS, " from ", TABLE_NAME, " where id=#{id}"})
    CorporationRole select(@Param("id") int id);

    @Select({"select ", SELECT_MESSAGE, " from ", TABLE_NAME, " where id=#{id}"})
    CorporationRole selectMessage(@Param("id") int id);

    @Select({"select ", SELECT_FIELDS, " from ", TABLE_NAME, " where corporation_name=#{corporationName}"})
    CorporationRole selectByName(@Param("corporationName") String corporationName);

    @Select({"select ", SELECT_FIELDS, " from ", TABLE_NAME, " where corporation_name like '%${corporationName}%'"})
    List<CorporationRole> fuzzySelectByName(@Param("corporationName") String corporationName);

    @Update({"update ", TABLE_NAME, " set corporation_name=#{corporationRole.corporationName}, corporation_address=#{corporationRole.corporationAddress}, " +
            "corporation_introduce=#{corporationRole.corporationIntroduce} where id=#{corporationRole.id}"})
    int update(@Param("corporationRole") CorporationRole corporationRole);

}
